package sing.cloud.alibaba.nacos.consumer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.concurrent.TimeUnit;

/**
 * @author xing
 * @date 2022/8/24 21:35
 */
@SpringBootApplication
public class NacosConfigConsumerApplication {
    public static void main(String[] args) throws InterruptedException {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(NacosConfigConsumerApplication.class, args);
        while (true) {
            // 当动态配置刷新时，会更新到 Enviroment中，因此这里每隔一秒中从Enviroment中获取配置
            String username = applicationContext.getEnvironment().getProperty("user.name");
            String userAge = applicationContext.getEnvironment().getProperty("user.age");
            String env = applicationContext.getEnvironment().getProperty("current-env");
            System.out.println("用户名: " + username + ", age: " + userAge + ", env: " + env);
            TimeUnit.SECONDS.sleep(1);
        }
    }
}
